﻿namespace EFS.RC.CC.Deployment.Tables.Tools
{
	public static class AgentDistributions
	{
		/// GetByCustomerEndPointID
		public static EFS.RC.CC.Deployment.Entities.Operators.Distribution[] GetByCustomerEndPointID(System.Int32 customerEndPointID)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// get data
				return connection.DoExecuteTableReaderQuery<EFS.RC.CC.Deployment.Entities.Operators.Distribution>(
					"[dbo].[AgentDistributions_GetByCustomerEndPointID]",
					new EFS.DB.Parameters.Array("customer_endpoint_id", customerEndPointID),
					EFS.RC.CC.Deployment.Tables.DataRow.Operators.Distribution.Load);
			}
		}

		/// Create
		public static void Create(
			System.Int32 agentID,
			System.Int32 customerEndPointID,
			EFS.DB.Connection connection)
		{
			// check
			EFS.Common.Verify.Reference(connection, "connection");

			// get data
			connection.DoExecuteNonQuery(
				"[dbo].[AgentDistributions_Create]",
				new EFS.DB.Parameters.Array(
					new System.String[] { "agent_id", "customer_endpoint_id" },
					new System.Object[] { agentID, customerEndPointID }));
		}

		/// Create
		public static void CreateIfNotExists(
			System.Int32 agentID,
			System.Int32 customerEndPointID)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// parameters array
				EFS.DB.Parameters.Array parametersArray = new EFS.DB.Parameters.Array(
						new System.String[] { "agent_id", "customer_endpoint_id" },
						new System.Object[] { agentID, customerEndPointID },
						new System.Boolean[] { false, false });

				// execute
				connection.DoExecuteNonQuery("[dbo].[AgentDistributions_CreateIfNotExists]", parametersArray);
			}
		}

		/// Delete
		public static void Delete(
			System.Int32 agentID,
			System.Int32 customerEndPointID)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// get data
				connection.DoExecuteNonQuery(
					"[dbo].[AgentDistributions_Delete]",
					new EFS.DB.Parameters.Array(
						new System.String[] { "agent_id", "customer_endpoint_id" },
						new System.Object[] { agentID, customerEndPointID }));
			}
		}

		/// DeleteByAgentID
		public static void DeleteByAgentID(
			System.Int32 agentID,
			EFS.DB.Connection connection)
		{
			// check
			EFS.Common.Verify.Reference(connection, "connection");

			// get data
			connection.DoExecuteNonQuery(
				"[dbo].[AgentDistributions_DeleteByAgentID]",
				new EFS.DB.Parameters.Array("agent_id", agentID));
		}

		/// DeleteByCustomerEndpointID
		public static void DeleteByCustomerEndpointID(
			System.Int32 ID,
			EFS.DB.Connection connection)
		{
			// check
			EFS.Common.Verify.Reference(connection, "connection");

			// get data
			connection.DoExecuteNonQuery(
				"[dbo].[AgentDistributions_DeleteByCustomerEndpointID]",
				new EFS.DB.Parameters.Array("id", ID));
		}
	}
}